package com.example.androidmainshixun.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.example.androidmainshixun.R;
import com.example.androidmainshixun.entity.Goods;

import java.util.List;

public class GoodsAdapter extends ArrayAdapter<Goods> {
    public GoodsAdapter(Context context, List<String> goodsList) {
        super(context, 0);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // 重用已有的视图或创建新的视图
        View view = convertView != null ? convertView : LayoutInflater.from(getContext()).inflate(R.layout.list_item, parent, false);

        // 获取当前位置的商品数据
        Goods goods = getItem(position);

        // 绑定数据到视图
        TextView textView = view.findViewById(R.id.title);
        textView.setText(goods.getName());

        return view;
    }
}
